<%include pub/head.html%>
</head>
  <body class="bodybg">
    <%include pub/nav.html%>
    <%include pub/userhead.html%>
	<div class="xu-mian-panel">
        <div class="container">
        	<!-- Tab panes -->
            <div class="row">
                <div class="col">
                <% if (locals.user){ %>
                <div class="other-words-bar" id="liuyanban">
                    <div class="ot-add-comment">
                        <div class="po-re">
                            <textarea class="form-control" rows="4" maxlength="140" placeholder="文明发言，建设和谐社区环境，记得保持言论友善和谦虚哦，互相学习，共同进步。"></textarea>
                            <p class="hky-write">还可以输入<span>140</span>个字</p>
                        </div>
                        <button class="ot-send-btn" disabled="disabled" type="button" id="uot-send-btn" fid="<%- locals.user._id%>">留言</button>
                    </div>
                </div>
                <% }else{ %>
                <div class="other-words-bar" id="liuyanban">
                    <div class="ly-title">
                        <h3>留言小板_</h3>
                        <span><a href="javascript:;" data-toggle="modal" data-target="#login">登录</a>之后才能留言</span>
                    </div>
                </div>
                <%}%>
                <%if (ucomments){%>
                <input type="hidden" value="<%= pagecount%>" id="compagecount">
                <input type="hidden" value="<%= compageid%>" id="compageid">
                <div class="ot-common-words">
                <%if(locals.user){%>
                    <% 
                    let zan_user_id = locals.user._id;
                    for(let i=0; i<ucomments.length; i++){ 
                    let replyList = ucomments[i].reply, 
                        zanNum = ucomments[i].zan,
                        zanList = ucomments[i].zanlist;
                    let hadzan = zanList.indexOf(zan_user_id);
                    %>
                    <div class="ot-common-item row" id="<%- ucomments[i]._id %>">
                        <div class="ot-item-left">
                            <a href="/users/userindex/<%- ucomments[i].fromid._id %>"><img src="<%- ucomments[i].fromid.headimg %>" width="50" height="50"></a>
                        </div>
                        <div class="ot-item-content">
                            <div class="row">
                                <div class="ot-user-name"><a href="/users/userindex/<%- ucomments[i].fromid._id %>"><%- ucomments[i].fromid.nickname %></a><span class="commenttime"><%- ucomments[i].time %></span></div>
                                <div class="ot-cont-bottom" uid="<%- ucomments[i].fromid._id %>" cid="<%- ucomments[i]._id %>">
                                    <p class="ot-user-cont"><%- ucomments[i].content %></p>
                                    <div class="ot-user-controls">
                                        <% if(hadzan !== -1){%>
                                        <span class="f-user-zan fu-zan ac"><i class="icon-heart"></i> <span zannum="<%- zanNum %>"><%- zanNum %></span></span>
                                        <%}else{%>
                                        <span class="f-user-zan fu-zan"><i class="icon-heart"></i> <span zannum="<%- zanNum %>"><%- zanNum %></span></span>
                                        <%}%>
                                        <span class="uot-comment-second"><i class="icon iconfont icon-comment_fill_light"></i> 回复</span>
                                        <% if(locals.user._id == ucomments[i].fromid._id){ %>
                                        <span class="uot-comment-delete dismiss" types="fcom"><i class="icon iconfont icon-deletefill"></i> 删除</span>
                                        <%}else{%>
                                        <span class="uot-comment-tip dismiss" types="ftip"><i class="icon iconfont icon-warnfill"></i> 举报</span>
                                        <%}%>
                                    </div>
                                </div>
                            </div>

                            <div class="ot-common-item2">
                                <% for(let ii=0; ii<replyList.length; ii++){
                                let szanNum = replyList[ii].zan,
                                    szanList = replyList[ii].zanlist,
                                    shadzan = szanList.indexOf(zan_user_id);
                                %>
                                <div class="second-ot-comment row" id="<%- replyList[ii]._id %>">
                                    <div class="ot-item-left">
                                        <a href="/users/userindex/<%- replyList[ii].fromid._id %>"><img src="<%- replyList[ii].fromid.headimg %>" width="50" height="50"></a>
                                    </div>
                                    <div class="ot-item-content">
                                        <div class="row">
                                            <div class="ot-user-name"><a href="/users/userindex/<%- replyList[ii].fromid._id %>"><%- replyList[ii].fromid.nickname %></a><span class="commenttime"><%- replyList[ii].time %></span></div>
                                            <div class="ot-cont-bottom" uid="<%- replyList[ii].fromid._id %>" cid="<%- ucomments[i]._id %>" tid="<%- replyList[ii]._id %>" >
                                                <p class="ot-user-cont"><span class="tosome-sp">@<a href="/users/userindex/<%- replyList[ii].toid._id %>"><%- replyList[ii].toid.nickname %></a>：</span><%- replyList[ii].content %></p>
                                                <div class="ot-user-controls">
                                                    <% if(shadzan !== -1){%>
                                                    <span class="s-user-zan su-zan ac"><i class="icon-heart"></i> <span zannum="<%- szanNum %>"><%- szanNum %></span></span>
                                                    <%}else{%>
                                                    <span class="s-user-zan su-zan"><i class="icon-heart"></i> <span zannum="<%- szanNum %>"><%- szanNum %></span></span>
                                                    <%}%>
                                                    <span class="uot-comment-second"><i class="icon iconfont icon-comment_fill_light"></i> 回复</span>
                                                    <% if(locals.user._id == replyList[ii].fromid._id){ %>
                                                    <span class="uot-comment-delete dismiss" tid="<%- replyList[ii]._id %>" types="scom"><i class="icon iconfont icon-deletefill"></i> 删除</span>
                                                    <%}else{%>
                                                    <span class="uot-comment-tip dismiss" tid="<%- replyList[ii]._id %>" types="stip"><i class="icon iconfont icon-warnfill"></i> 举报</span>
                                                    <%}%>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <% } %>
                            </div>
                        </div>
                    </div>
                    <%}%>
                <%}else{%>
                    <%if(ucomments.length == 0){%>
                    <div class="nocomment-bar">
                    	<i class="icon iconfont icon-discover"></i>暂无留言
                    </div>
                    <%}else{%>
	                    <% 
	                    for(let i=0; i<ucomments.length; i++){ 
	                    let replyList = ucomments[i].reply, 
	                        zanNum = ucomments[i].zan,
	                        zanList = ucomments[i].zanlist;
	                    %>
	                    <div class="ot-common-item row">
	                        <div class="ot-item-left">
	                            <a href="/users/userindex/<%- ucomments[i].fromid._id %>" target="_blank"><img src="<%- ucomments[i].fromid.headimg %>" width="50" height="50"></a>
	                        </div>
	                        <div class="ot-item-content">
	                            <div class="row">
	                                <div class="ot-user-name"><a href="/users/userindex/<%- ucomments[i].fromid._id %>" target="_blank"><%- ucomments[i].fromid.nickname %></a><span class="commenttime"><%- ucomments[i].time %></span></div>
	                                <div class="ot-cont-bottom" uid="<%- ucomments[i].fromid._id %>" cid="<%- ucomments[i]._id %>">
	                                    <p class="ot-user-cont"><%- ucomments[i].content %></p>
	                                </div>
	                            </div>

	                            <div class="ot-common-item2">
	                                <% for(let ii=0; ii<replyList.length; ii++){
	                                let szanNum = replyList[ii].zan,
	                                    szanList = replyList[ii].zanlist;
	                                %>
	                                <div class="second-ot-comment row">
	                                    <div class="ot-item-left">
	                                        <a href="/users/userindex/<%- replyList[ii].fromid._id %>" target="_blank"><img src="<%- replyList[ii].fromid.headimg %>" width="50" height="50"></a>
	                                    </div>
	                                    <div class="ot-item-content">
	                                        <div class="row">
	                                            <div class="ot-user-name"><a href="/users/userindex/<%- replyList[ii].fromid._id %>" target="_blank"><%- replyList[ii].fromid.nickname %></a><span class="commenttime"><%- replyList[ii].time %></span></div>
	                                            <div class="ot-cont-bottom" uid="<%- replyList[ii].fromid._id %>" cid="<%- ucomments[i]._id %>" tid="<%- replyList[ii]._id %>" >
	                                                <p class="ot-user-cont"><span class="tosome-sp">@<a href="/users/userindex/<%- replyList[ii].toid._id %>"><%- replyList[ii].toid.nickname %></a>：</span><%- replyList[ii].content %></p>
	                                            </div>
	                                        </div>
	                                    </div>
	                                </div>
	                                <% } %>
	                            </div>
	                        </div>
	                    </div>
	                    <%}%>
                    <%}%>
                </div>
                <div class="pager row" id="comment-pagination"></div>
                <% }} %>
                </div>
            </div>
        </div>
    </div>
    </div>
    <%include pub/foot.html%>
    <div class="modal slide modal-small" id="deleteComment" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">提醒</h4>
              </div>
              <div class="modal-body delete-modal-body">
                <input type="hidden" id="deletecid-f">
                <input type="hidden" id="deletecid-s">
                确认要删除此条评论么？
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="delete-comf-btn">删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
              </div>
            </div>
        </div>
    </div>
    <div class="modal slide modal-small" id="tipComment" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">举报原因</h4>
              </div>
              <div class="modal-body delete-modal-body">
                <input type="hidden" id="tipcid-f">
                <input type="hidden" id="tipcid-s">
                <textarea class="form-control" rows="4" id="tip-comf-val"></textarea>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="tip-comf-btn">确认举报</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
              </div>
            </div>
        </div>
    </div>
    <%include pub/script.html%>
    <script type="text/javascript">
    	$(function(){
    		let user_page_id = $('#userid-page').val();
	        var limittxt = 'page=';
	        var countnums = $('#compagecount').val();
	        var currentPage = parseInt($('#compageid').val());
	        if(countnums >  19 ){
	            var total = Math.ceil(countnums/20);
	            var prev = currentPage -1;
	            var next = currentPage +1;
	            $.jqPaginator('#comment-pagination', {
	                totalPages: total,
	                visiblePages:5,
	                currentPage:currentPage,
	                prev: '<li class="prev"><a href="/users/usercomment'+user_page_id+'?'+limittxt+prev+'" >&lt</a></li>',
					next: '<li><a href="/users/usercomment'+user_page_id+'?'+limittxt+next+'">&gt</a></li>',
					page: '<li class="page"><a href="/users/usercomment/'+user_page_id+'?'+limittxt+'{{page}}">{{page}}</a></li>',
	            });
	        }
	    })
    </script>
  </body>
</html>